﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="HttpHelper.cs" company="VCD">
//   (C) 2010
// </copyright>
// <summary>
//   Defines the HttpHelper type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Id3stuff
{
    using System.IO;
    using System.Net;

    public class HttpHelper
    {
        public string DownloadWebPage(string url)
        {
            var webRequestObject = (HttpWebRequest)WebRequest.Create(url);
            webRequestObject.UserAgent = ".NET Framework/2.0";
            WebResponse response = webRequestObject.GetResponse();
            var webStream = response.GetResponseStream();
            if (webStream != null)
            {
                var reader = new StreamReader(webStream);
                var pageContent = reader.ReadToEnd();
                reader.Close();
                webStream.Close();
                response.Close();

                return pageContent;
            }

            return string.Empty;
        }

        public System.Drawing.Image DownloadImage(string url)
        {
            var client = new WebClient();
            Stream stream = client.OpenRead(url);
            // bitmap = new Bitmap(stream);
            var image = System.Drawing.Image.FromStream(stream);
            stream.Flush();
            stream.Close();
            return image;
        }
    }
}
